﻿<link href="~/layuiadmin/layui/css/layui.css" rel="stylesheet" />
<script src="~/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/xadmin/js/xadmin.js"></script>

<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" href="/Home/main?name={{d.fileName}}">查看日记</a>
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test'
            , height: 'full-20'
            , url: '/home/GetLogs'
            , toolbar: '#toolbarDemo'
            , title: 'IIS访问日记'
            , cols: [[
                { type: 'checkbox', fixed: 'left' }
                , { field: 'fileName', title: '文件名', fixed: 'left', unresize: true, sort: true }
                , { field: 'fileFullName', title: '文件路径' }
                , { field: 'fileSize', title: '文件大小（M）' }
                , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
            ]]
            , limits: [10, 15, 40, 60, 80, 100, 200, 400]
            , limit: 100 //默认采用10
            , page: true
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.prompt({
                    formType: 2
                    , value: data.email
                }, function (value, index) {
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
    });

</script>